<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/%E6%AD%A6%E6%B1%8932x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/%E6%AD%A6%E6%B1%8916x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib1/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib1/pace/pace-theme-center-simple.min.css">
  <script src="/lib1/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="组件创建与开发本文档适用于使用 &amp;#98;&amp;#117;&amp;#x69;&amp;#108;&amp;#x64;&amp;#45;&amp;#x70;&amp;#x6c;&amp;#117;&amp;#x67;&amp;#x69;&amp;#110;&amp;#45;&amp;#99;&amp;#111;&amp;#x6d;&amp;#x70;&amp;#x6f;&amp;#110;&amp;#x65;&amp;#110;&amp;#116;&amp;#64;&amp;#x31;&amp;#46;&amp;#x78; 的组件工程，如果使用的是 build-plugin-rax-com">
<meta property="og:type" content="article">
<meta property="og:title" content="Rax组件开发">
<meta property="og:url" content="http://example.com/2021/11/26/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88%E5%88%9D%E5%AD%A6/Rax%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91/index.html">
<meta property="og:site_name" content="Technological Blog">
<meta property="og:description" content="组件创建与开发本文档适用于使用 &amp;#98;&amp;#117;&amp;#x69;&amp;#108;&amp;#x64;&amp;#45;&amp;#x70;&amp;#x6c;&amp;#117;&amp;#x67;&amp;#x69;&amp;#110;&amp;#45;&amp;#99;&amp;#111;&amp;#x6d;&amp;#x70;&amp;#x6f;&amp;#110;&amp;#x65;&amp;#110;&amp;#116;&amp;#64;&amp;#x31;&amp;#46;&amp;#x78; 的组件工程，如果使用的是 build-plugin-rax-com">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-11-26T04:18:39.000Z">
<meta property="article:modified_time" content="2021-11-24T08:44:54.114Z">
<meta property="article:author" content="Li Yudong">
<meta property="article:tag" content="公司技术栈">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/2021/11/26/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88%E5%88%9D%E5%AD%A6/Rax%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Rax组件开发 | Technological Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Technological Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">IT小白的成长之旅</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa-fw"></i>标签<span class="badge">18</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa-fw"></i>分类<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa-fw"></i>归档<span class="badge">95</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/tiarmor1" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/11/26/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88%E5%88%9D%E5%AD%A6/Rax%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/author.jpg">
      <meta itemprop="name" content="Li Yudong">
      <meta itemprop="description" content="">
    </span>
    
    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Technological Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Rax组件开发
        </h1>
    
        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
    
              <time title="创建时间：2021-11-26 12:18:39" itemprop="dateCreated datePublished" datetime="2021-11-26T12:18:39+08:00">2021-11-26</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-11-24 16:44:54" itemprop="dateModified" datetime="2021-11-24T16:44:54+08:00">2021-11-24</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88/" itemprop="url" rel="index"><span itemprop="name">盒马技术栈</span></a>
                </span>
            </span>
    
          
    
        </div>
      </header>
    
    
    
    
    <div class="post-body" itemprop="articleBody">
    
      
        <h1 id="组件创建与开发"><a href="#组件创建与开发" class="headerlink" title="组件创建与开发"></a>组件创建与开发</h1><p>本文档适用于使用 <a href="mailto:&#98;&#117;&#x69;&#108;&#x64;&#45;&#x70;&#x6c;&#117;&#x67;&#x69;&#110;&#45;&#99;&#111;&#x6d;&#x70;&#x6f;&#110;&#x65;&#110;&#116;&#64;&#x31;&#46;&#x78;">&#98;&#117;&#x69;&#108;&#x64;&#45;&#x70;&#x6c;&#117;&#x67;&#x69;&#110;&#45;&#99;&#111;&#x6d;&#x70;&#x6f;&#110;&#x65;&#110;&#116;&#64;&#x31;&#46;&#x78;</a> 的组件工程，如果使用的是 build-plugin-rax-component 请按照文档进行升级</p>
<p>Rax 业务组件开发基于 <code>build-scripts</code> 的工程生态，满足组件开发过程中各种复杂场景。在 Rax 组件开发工程中提供了多端构建的支持，并且融合了强大的 Markdown 解析能力，让开发者能够在编写 demo 的同时能够生成对应的组件文档。欢迎通过 <a href="https://github.com/ice-lab/iceworks-cli/issues" target="_blank" rel="noopener">issue</a> 反馈问题。</p>
<h2 id="组件创建"><a href="#组件创建" class="headerlink" title="组件创建"></a>组件创建</h2><p>如果是阿里内部同学并需要接入天马或 DEF，请务必参考文档 <a href="https://yuque.alibaba-inc.com/rax-docs/ofau5b/urrtn0" target="_blank" rel="noopener">组件开发接入 DEF/天马</a> 创建组件。</p>
<p>通过 CLI 创建：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">➜ npm init rax component</span><br><span class="line">? What&#39;s your project type?</span><br><span class="line">  App (Build universal application)</span><br><span class="line">❯ Component (Build universal component)</span><br><span class="line">  API (Build universal API library)</span><br><span class="line">  Plugin (Build plugin for miniapp)</span><br></pre></td></tr></table></figure>

<p>组件开发调试：</p>
<p>进入到组件目录，执行 <code>npm start</code> 即可启动调试：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ cd rax-component</span><br><span class="line">$ npm install</span><br><span class="line">$ npm start</span><br></pre></td></tr></table></figure>

<h2 id="组件目录"><a href="#组件目录" class="headerlink" title="组件目录"></a>组件目录</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">├── miniapp-demo              # 小程序开发 demo（可选）</span><br><span class="line">│    └── index.tsx</span><br><span class="line">├── demo                      # 组件 demo</span><br><span class="line">│    ├── simple.md</span><br><span class="line">│    └── usage.md</span><br><span class="line">├── src                       # 组件源码</span><br><span class="line">│    └── index.tsx</span><br><span class="line">├── build.json                # 构建配置</span><br><span class="line">├── lib&#x2F;                      # 构建产物，编译为 ES5 的代码</span><br><span class="line">├── es&#x2F;                       # 构建产物，编译为 es module 规范的代码</span><br><span class="line">├── build&#x2F;                    # 构建产物，用于组件文档&#x2F;demo 预览</span><br><span class="line">├── README.md</span><br><span class="line">└── package.json</span><br></pre></td></tr></table></figure>

<p>组件入口：</p>
<p>组件入口为 <code>src/index.tsx</code>：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; createElement &#125; <span class="keyword">from</span> <span class="string">'rax'</span>;</span><br><span class="line"><span class="keyword">import</span> View <span class="keyword">from</span> <span class="string">'rax-view'</span>;</span><br><span class="line"><span class="keyword">import</span> Text <span class="keyword">from</span> <span class="string">'rax-text'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> MyComponent = <span class="function">(<span class="params">props</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    &lt;View&gt;</span><br><span class="line">      &lt;Text&gt;Hello World!&lt;<span class="regexp">/Text&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>View&gt;</span><br><span class="line">  );</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> MyComponent;</span><br></pre></td></tr></table></figure>

<p>编写 demo：</p>
<p>组件的文档位于 <code>demo</code> 目录下，工程启动后会默认启动文档预览页面，可以通过预览页面进行组件功能调试和文档的预览。 demo 文件使用 <code>yaml-markdown</code> 语法，通过增加 <code>*.md</code> 文件来创建多个组件 demo。</p>
<p>md 文件的形式如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: Baisc</span><br><span class="line">order: 1</span><br><span class="line">---</span><br><span class="line"></span><br><span class="line">basic usage</span><br><span class="line"></span><br><span class="line">&#96;&#96;&#96;jsx</span><br><span class="line">import &#123; createElement &#125; from &#39;rax&#39;;</span><br><span class="line">import MyComponent from &#39;example-component&#39;;</span><br><span class="line"></span><br><span class="line">function App()&#123;</span><br><span class="line">  return &lt;MyComponent &#x2F;&gt;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">export default App;</span><br><span class="line">&#96;&#96;&#96;</span><br></pre></td></tr></table></figure>

<p>工程上将 jsx 语言的代码块当做组件进行渲染，该代码块需要像上述示例中通过 <code>export default</code> 导出需要渲染的组件。</p>
<p>小程序调试：</p>
<p>小程序调试时，工程会默认按小程序配置生成对应的模版文件，默认位于 <code>.miniapp</code> 目录中。 如果有自定义属性调试需求，可以在项目目录中增加 <code>miniapp-demo/index.js</code> 文件：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">import &#123; createElement &#125; from &#39;rax&#39;;</span><br><span class="line">import MyComponent from &#39;..&#x2F;src&#x2F;index&#39;;</span><br><span class="line"></span><br><span class="line">function App()&#123;</span><br><span class="line">  &#x2F;&#x2F; 根据需求传入自定义属性</span><br><span class="line">  return &lt;MyComponent cutomProps&#x3D;&#123;&#123;&#125;&#125; &#x2F;&gt;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">export default App;</span><br></pre></td></tr></table></figure>

<h2 id="cli-参数"><a href="#cli-参数" class="headerlink" title="cli 参数"></a>cli 参数</h2><p>–watch-dist：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm start -- --watch-dist</span><br></pre></td></tr></table></figure>

<p>通过指定 <code>--watch-dist</code> 参数后，文件的变化实时构建到 dist 目录下。</p>
<p>–skip-demo：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ npm start -- --skip-demo</span><br><span class="line"></span><br><span class="line"># or</span><br><span class="line">$ npm run build -- --skip-demo</span><br></pre></td></tr></table></figure>

<p>通过指定 <code>--skip-demo</code> 参数后，不构建 demo 产物。</p>
<h2 id="组件工程配置"><a href="#组件工程配置" class="headerlink" title="组件工程配置"></a>组件工程配置</h2><p>rax 组件工程需要在 <code>build.json</code> 中引入 <code>build-plugin-component</code>，并设置组件类型为 <code>rax</code>：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"type"</span>: <span class="string">"rax"</span>,</span><br><span class="line">  <span class="attr">"targets"</span>: [<span class="string">"web"</span>],</span><br><span class="line">  <span class="attr">"plugins"</span>: [</span><br><span class="line">    <span class="string">"build-plugin-component"</span></span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>插件支持配置参数如下：</p>
<p>targets：</p>
<ul>
<li>类型：array</li>
<li>默认值：[]</li>
</ul>
<p>通过配置 <code>targets</code> 执行多端构建产物，可选值分别为 web、weex、miniapp、kraken、wechat-miniprogram 和 node。</p>
<p>miniapp：</p>
<p>当 targets 包含 miniapp 时，通过 <code>miniapp</code> 配置小程序端的独有配置。配置项如下：</p>
<p>buildType</p>
<ul>
<li>类型：string</li>
<li>默认值：compile</li>
</ul>
<p>小程序引擎选择，默认为编译时引擎。如需开启运行时引擎，则可配置为 <code>runtime</code>。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">"miniapp": &#123;</span><br><span class="line">  "buildType": "runtime"  // 开启运行时引擎</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>需要注意的是，当工程从编译时引擎切换为运行时引擎，需要删除 <code>package.json</code> 的 codeminiappConfig 字段。否则，rax 项目工程会将该组件识别为编译时组件。</p>
<p>注：微信小程序端配置项同上，但是需要在 <code>wechat-miniprogram</code> 中配置，例如：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">"wechat-miniprogram": &#123;</span><br><span class="line">   "buildType": "runtime"  // 开启运行时引擎</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>inlineStyle</p>
<ul>
<li>类型：boolean</li>
<li>默认值：true</li>
</ul>
<p>构建 dist 产物时是否以 inline 的方式进行构建。</p>
<blockquote>
<p>weex 构建样式内容强制以 inline 方式输出</p>
</blockquote>
<p>enablePlatformLoader</p>
<ul>
<li>类型：boolean</li>
<li>默认值：false</li>
</ul>
<p>指定构建产物中是否按端移除代码，web 端构建时，以下内容将会被简化。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; isWeex, isWeb &#125; <span class="keyword">from</span> <span class="string">'universal-env'</span></span><br></pre></td></tr></table></figure>

<p>将被替换成</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> isWeex = <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">const</span> isWeb = <span class="literal">true</span>;</span><br></pre></td></tr></table></figure>

<p>源码中 isWeex 中的相关逻辑将被识别为 deadcode 而被移除。</p>
<p>mockNodeEnv</p>
<ul>
<li>类型：boolean ｜ object</li>
<li>默认值：true</li>
</ul>
<p>同 <a href="https://webpack.js.org/configuration/node/#node" target="_blank" rel="noopener">webpack Node 配置</a>，默认开启，提供 node 环境下的 mock 变量。</p>
<p>devServer</p>
<ul>
<li>类型：object</li>
<li>默认值：<code>{ hot: true, disableHostCheck: true, clientLogLevel: &#39;silent&#39; }</code></li>
</ul>
<p>同 <a href="https://webpack.js.org/configuration/dev-server/" target="_blank" rel="noopener">webpack devServer 配置</a>，自定义配置将会与默认配置合并。</p>
<p>sourceMap</p>
<ul>
<li>类型：boolean | string</li>
<li>默认值：false</li>
</ul>
<p>如果打包 library 到 dist 目录，用来配置是否产出 sourceMap 文件。具体可配置项可参考<a href="https://webpack.js.org/configuration/devtool/#devtool" target="_blank" rel="noopener"> webpack devtool 配置</a>，如果设置为 true 则默认使用 <code>source-map</code> 值。</p>
<p>disableUMD</p>
<ul>
<li>类型：boolean</li>
<li>默认值：false</li>
</ul>
<p>开启后将不会输出 UMD 产物。</p>
<p>library</p>
<p>构建 UMD 产物时，配置 webpack 的 <a href="https://webpack.js.org/configuration/output/#outputlibrary" target="_blank" rel="noopener">output.library</a> 属性。</p>
<p>minify</p>
<ul>
<li>类型：boolean</li>
<li>默认：false</li>
</ul>
<p>如果打包 library 到 dist 目录，配置打包文件是否压缩。</p>
<p>outputDir</p>
<p><code>npm run build</code> 构建时，小程序产物构建的目录。默认为 <code>lib</code>。</p>
<p>htmlInjection</p>
<ul>
<li>类型：object</li>
<li>默认：{}</li>
</ul>
<p>往预览的 demo 中注入自定义内容，比如插入一些静态脚本、css reset 资源等：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"htmlInjection"</span>: &#123;</span><br><span class="line">    <span class="attr">"headAppend"</span>: [</span><br><span class="line">      <span class="string">"&lt;script src='http://foo.com/a.js' /&gt;"</span>,</span><br><span class="line">      <span class="string">"&lt;link href='http://foo.com/a.css' /&gt;"</span></span><br><span class="line">    ],</span><br><span class="line">    <span class="attr">"headPrepend"</span>: [],</span><br><span class="line">    <span class="attr">"bodyAppend"</span>: [],</span><br><span class="line">    <span class="attr">"bodyPrepend"</span>: [],</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>分别对应 html 中的四个位置：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">%=</span> <span class="attr">headPrepend</span> %&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>Demo 预览 <span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">%=</span> <span class="attr">headAppend</span> %&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">%=</span> <span class="attr">bodyPrepend</span> %&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"root"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">%=</span> <span class="attr">bodyAppend</span> %&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="组件工程升级"><a href="#组件工程升级" class="headerlink" title="组件工程升级"></a>组件工程升级</h2><p>从 plugin-rax-component 升级到 plugin-component：</p>
<p>升级原因：</p>
<ul>
<li>为了保证 React&amp;Rax 组件工程能力一致，我们将 plugin-rax-component 统一合并到 plugin-component 上</li>
<li>Rax 组件工程对原先工程能力进行的全面升级，更加合理地组织组件目录，并提供重构优化了组件构建和文档预览能力</li>
</ul>
<h3 id="修改-package-json-依赖"><a href="#修改-package-json-依赖" class="headerlink" title="修改 package.json 依赖"></a>修改 package.json 依赖</h3><p>组件工程依赖插件从 <code>build-plugin-rax-component</code> 升级为 <code>build-plugin-component</code>：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">-  "build-plugin-rax-component": "^0.2.14",</span><br><span class="line">+  "build-plugin-component": "^1.0.0"</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="修改-build-json-配置"><a href="#修改-build-json-配置" class="headerlink" title="修改 build.json 配置"></a>修改 build.json 配置</h3><p>原先 <code>build-plugin-rax-component</code> 组件配置项，均升级为顶层配置</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">+  "type": "rax",</span><br><span class="line">+  "targets": ["web"],</span><br><span class="line">+  "inlineStyle": true,</span><br><span class="line">  "plugins": [</span><br><span class="line">-    ["build-plugin-rax-component", &#123;</span><br><span class="line">-      "type": "rax",</span><br><span class="line">-      "targets": ["web"],</span><br><span class="line">-      "forceInline": true</span><br><span class="line">-    &#125;]</span><br><span class="line">+    "build-plugin-component"</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>forceInline 配置变更为 inlineStyle，通过 Rax 工程配置保持一致</p>
</blockquote>
<h3 id="目录结构变化"><a href="#目录结构变化" class="headerlink" title="目录结构变化"></a>目录结构变化</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">  ├── demo                      # 组件 demo</span><br><span class="line">- │    ├── miniapp</span><br><span class="line">- │    ├── wechat-miniprogram</span><br><span class="line">- │    ├── index.jsx</span><br><span class="line">+ │    ├── simple.md</span><br><span class="line">+ │    └── usage.md</span><br><span class="line">+ ├── miniapp-demo              # 小程序 demo 调试代码（可选）</span><br><span class="line">+ │    └── index.tsx</span><br><span class="line">  ├── src                       # 组件源码</span><br><span class="line">  │    └── index.tsx</span><br><span class="line">  ├── build.json                # 构建配置</span><br><span class="line">  ├── lib&#x2F;                      # 构建产物，编译为 ES5 的代码</span><br><span class="line">  ├── es&#x2F;                       # 构建产物，编译为 es module 规范的代码</span><br><span class="line">  ├── build&#x2F;                    # 构建产物，用于组件文档&#x2F;demo 预览</span><br><span class="line">  ├── README.md</span><br><span class="line">  └── package.json</span><br></pre></td></tr></table></figure>

<p>具体变更内容如下：</p>
<ol>
<li>小程序相关的模版代码将自动生成，原 miniapp 目录移除，如果有自定义小程序 props 属性的测试需求，可以增加 miniapp-demo 目录</li>
<li>demo 目录下不再支持 index.j|tsx 文件，demo 文件均采用 *.md</li>
</ol>
<p>如组件工程迁移过程中遇到问题请通过 <a href="https://github.com/ice-lab/iceworks-cli/issues" target="_blank" rel="noopener">issue</a> 进行反馈。</p>
<h1 id="小程序组件开发"><a href="#小程序组件开发" class="headerlink" title="小程序组件开发"></a>小程序组件开发</h1><p>由于小程序开发模式的特殊性，本节单独介绍小程序组件的开发。</p>
<blockquote>
<p>注意：目前 Rax 组件开发默认使用编译时引擎，本文档也是基于编译时引擎介绍。其开发产物适用于原生小程序项目、Rax 编译时小程序项目及 Rax 运行时小程序项目。如果需要开发运行时组件（仅支持 Rax 运行时小程序项目），需要进行额外配置，详见组件创建与开发一节中组件工程配置里 <code>buildType</code> 的介绍。</p>
</blockquote>
<h2 id="开发"><a href="#开发" class="headerlink" title="开发"></a>开发</h2><p>因为 Rax 语法转换到小程序语法是通过 AST 编译实现的，所以目前存在两种小程序组件的开发模式：</p>
<ul>
<li>使用小程序原生语法</li>
<li>使用 Rax 语法</li>
</ul>
<p>我们将分别介绍两种开发模式。</p>
<p>使用 Rax 语法：</p>
<p>这种开发模式比较简单，你可以直接在 <code>src</code> 目录下使用其他 Rax 多端组件来完成你的多端组件，开发完后执行：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run build</span><br></pre></td></tr></table></figure>

<p>在 <code>lib/miniapp</code> 目录下你就可以看到转换后的组件代码，最后通过 npm 发布，即可在你的 Rax 多端工程项目中使用。</p>
<p>使用小程序原生语法：</p>
<p>由于需要避免转译器转译小程序原生组件，我们需要在 <code>build.json</code> 的 <code>targets</code> 字段中删掉 <code>miniapp</code>，然后在 <code>src</code> 目录下新建 <code>miniapp</code> 文件夹。现在，你就可以在该目录下完成小程序原生组件的编码了。编码完成后执行：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run build</span><br></pre></td></tr></table></figure>

<p>在 <code>lib/miniapp</code> 目录下你就可以看到你的原生小程序组件代码。最后通过 npm 发布，即可在你的 Rax 多端工程项目中使用。实际上，这里构建器只是做了复制的工作，把 <code>src</code> 目录下的 <code>miniapp</code> 原封不动的复制到了 <code>lib</code> 目录下。</p>
<p>开发预览：</p>
<p>你可以在小程序开发者工具中打开 <code>demo/ali-miniapp</code> 文件夹，然后修改 <code>pages/index.json</code> 中自定义组件的路径实现开发实时预览的效果。</p>
<h2 id="组件库开发"><a href="#组件库开发" class="headerlink" title="组件库开发"></a>组件库开发</h2><p>目前 Rax 已支持组件库开发，具体开发方式与开发单组件相比，区别在于导出方式。举例，项目结构如下所示：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">├── src</span><br><span class="line"> │   ├── components</span><br><span class="line"> │    │   ├── Button</span><br><span class="line"> │    │   │   └── index.tsx</span><br><span class="line"> │    │   └── Icon</span><br><span class="line"> │    │       └── index.tsx</span><br><span class="line"> │   └── index.tsx</span><br></pre></td></tr></table></figure>

<p><code>src/index.tsx</code> 内容如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> Button <span class="keyword">from</span> <span class="string">'./components/Button'</span>;</span><br><span class="line"><span class="keyword">import</span> Icon <span class="keyword">from</span> <span class="string">'./components/Icon'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> &#123;</span><br><span class="line">  Button,</span><br><span class="line">  Icon</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在执行 <code>npm run build</code> 后，可以看到 <code>lib/miniapp</code> 目录下存在编译后的小程序组件代码。此时，为确保该组件库发布后能正常在 Rax 项目中使用，需要在 <code>package.json</code> 中的 <code>miniappConfig</code> 字段进行如下配置：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">"miniappConfig": &#123;</span><br><span class="line">    "subPackages": &#123;</span><br><span class="line">      "Button": &#123;</span><br><span class="line">        "main": "lib/miniapp/components/Button/index"</span><br><span class="line">      &#125;,</span><br><span class="line">      "Icon": &#123;</span><br><span class="line">        "main": "lib/miniapp/components/Icon/index"</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<p>组件开发总结：</p>
<p>整个过程我们需要关注的是，在组件工程的 <code>package.json</code> 中存在 <code>miniappConfig</code> 字段，其中 <code>main</code> 属性表示构建后小程序代码的入口路径。在 Rax 多端工程构建的时候，会去读取整个字段的值，然后把该目录下的组件视作原生小程序组件。</p>
<h2 id="多态协议"><a href="#多态协议" class="headerlink" title="多态协议"></a>多态协议</h2><p>定义一套多态组件的配置协议，达到同一套代码在不同端的映射。使用 <code>package.json</code> 中的 <code>miniappConfig</code> 字段定义小程序组件配置。目前除 <code>main</code> 外其他字段尚未开始使用。以下是详细配置说明：</p>
<h3 id="多态组件协议"><a href="#多态组件协议" class="headerlink" title="多态组件协议"></a>多态组件协议</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"name"</span>: <span class="string">"rax-sample"</span>，</span><br><span class="line">  <span class="string">"miniappConfig"</span>: &#123;</span><br><span class="line">    <span class="comment">// 对应阿里小程序组件入口</span></span><br><span class="line">    <span class="attr">"main"</span>: <span class="string">"lib/miniapp/index"</span>,</span><br><span class="line">    <span class="comment">// 子组件配置</span></span><br><span class="line">    <span class="attr">"subComponents"</span>: &#123;</span><br><span class="line">      <span class="comment">// 子组件名称</span></span><br><span class="line">      <span class="attr">"Header"</span>: &#123;</span><br><span class="line">         <span class="comment">// 子组件入口</span></span><br><span class="line">        <span class="attr">"main"</span>: <span class="string">"lib/miniapp/header/index"</span></span><br><span class="line">      &#125;,</span><br><span class="line">      <span class="attr">"Cell"</span>: &#123;</span><br><span class="line">        <span class="attr">"main"</span>: <span class="string">"lib/miniapp/cell/index"</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 组件属性映射</span></span><br><span class="line">    <span class="attr">"propsMap"</span>:&#123;</span><br><span class="line">      <span class="attr">"source"</span>: <span class="string">"src"</span>,</span><br><span class="line">      <span class="attr">"onClick"</span>: <span class="string">"onTap"</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 组件标签映射</span></span><br><span class="line">    <span class="attr">"tagNameMap"</span>: <span class="string">"view"</span></span><br><span class="line">  &#125;,</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="多态组件库协议"><a href="#多态组件库协议" class="headerlink" title="多态组件库协议"></a>多态组件库协议</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"name"</span>: <span class="string">"rax-components-library"</span>，</span><br><span class="line">  <span class="string">"miniappConfig"</span>: &#123;</span><br><span class="line">   	<span class="attr">"subPackages"</span>:  &#123;</span><br><span class="line">	   <span class="attr">"Button"</span>: &#123;</span><br><span class="line">	     <span class="attr">"main"</span>: <span class="string">"lib/miniapp/Button/index"</span>,</span><br><span class="line">		&#125;,</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="comment">// 需要拷贝的公共文件或目录</span></span><br><span class="line">	<span class="attr">"public"</span>: [<span class="string">"utils.js"</span>, <span class="string">"static"</span>]</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>组件库使用方式举例：</p>
<figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; Button &#125; <span class="keyword">from</span> <span class="string">'fusion-mobile'</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> (props) =&gt; &#123;</span><br><span class="line">	<span class="keyword">return</span> (</span><br><span class="line">		&lt;View&gt;</span><br><span class="line">	  		&lt;Button&gt;hello world&lt;<span class="regexp">/Button&gt;</span></span><br><span class="line"><span class="regexp">	  	&lt;/</span>View&gt;</span><br><span class="line">	)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>
    
    
    
    
    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      
    </div>
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="Li Yudong 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Li Yudong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://example.com/2021/11/26/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88%E5%88%9D%E5%AD%A6/Rax%E7%BB%84%E4%BB%B6%E5%BC%80%E5%8F%91/" title="Rax组件开发">http://example.com/2021/11/26/盒马技术栈初学/Rax组件开发/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

    
      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E5%85%AC%E5%8F%B8%E6%8A%80%E6%9C%AF%E6%A0%88/" rel="tag"># 公司技术栈</a>
          </div>
    
        

    
        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/11/24/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88%E5%88%9D%E5%AD%A6/Rax%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%BA%94%E7%94%A8/" rel="prev" title="Rax小程序应用">
      <i class="fa fa-chevron-left"></i> Rax小程序应用
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/11/26/%E7%9B%92%E9%A9%AC%E6%8A%80%E6%9C%AF%E6%A0%88%E5%88%9D%E5%AD%A6/Rax%E5%B0%8F%E7%A8%8B%E5%BA%8F%E8%BF%9B%E9%98%B6/" rel="next" title="Rax小程序进阶">
      Rax小程序进阶 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#组件创建与开发"><span class="nav-number">1.</span> <span class="nav-text">组件创建与开发</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#组件创建"><span class="nav-number">1.1.</span> <span class="nav-text">组件创建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#组件目录"><span class="nav-number">1.2.</span> <span class="nav-text">组件目录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#cli-参数"><span class="nav-number">1.3.</span> <span class="nav-text">cli 参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#组件工程配置"><span class="nav-number">1.4.</span> <span class="nav-text">组件工程配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#组件工程升级"><span class="nav-number">1.5.</span> <span class="nav-text">组件工程升级</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#修改-package-json-依赖"><span class="nav-number">1.5.1.</span> <span class="nav-text">修改 package.json 依赖</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改-build-json-配置"><span class="nav-number">1.5.2.</span> <span class="nav-text">修改 build.json 配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#目录结构变化"><span class="nav-number">1.5.3.</span> <span class="nav-text">目录结构变化</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#小程序组件开发"><span class="nav-number">2.</span> <span class="nav-text">小程序组件开发</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#开发"><span class="nav-number">2.1.</span> <span class="nav-text">开发</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#组件库开发"><span class="nav-number">2.2.</span> <span class="nav-text">组件库开发</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#多态协议"><span class="nav-number">2.3.</span> <span class="nav-text">多态协议</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#多态组件协议"><span class="nav-number">2.3.1.</span> <span class="nav-text">多态组件协议</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#多态组件库协议"><span class="nav-number">2.3.2.</span> <span class="nav-text">多态组件库协议</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Li Yudong"
      src="/images/author.jpg">
  <p class="site-author-name" itemprop="name">Li Yudong</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">95</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/tiarmor1" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;tiarmor1" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1157019137@qq.com" title="E-Mail → mailto:1157019137@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2020 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Li Yudong</span>
</div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,0' opacity='0.5' zIndex='-1' count='150' src="/lib1/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib1/anime.min.js"></script>
  <script src="/lib1/velocity/velocity.min.js"></script>
  <script src="/lib1/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  
   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/fireworks.js"></script>
  
</body>
</html>

